<?php
namespace Admin\Controller;
use Think\Controller;

/**
* 
*/
class UserController extends CommonController{
	public function add(){
		if(IS_POST){
			$model=M('User');
			$data=I('post.');
			$data['addtime']=time();
			$data['like']=implode(',',$data['like']);
			$result=$model->add($data);
			if($result){
				$this->success('添加成功！',U('showList'),3);
			}else{
				$this->error('添加失败');
			}
		}else{
			$model=M('Dept');
			$data=$model->select();
			$this->assign('data',$data);
			$this->display();
		}
	}
	public function showList(){
		$model=M('User');
		$count=$model->count();
		$page=new \Think\Page($count,5);
		$page -> rollPage=5;
		$page -> lastSuffix=false;
		$page -> setConfig('prev','上一页');
		$page -> setConfig('next','下一页');
		$page -> setConfig('last','末页');
		$page -> setConfig('first','首页');
		$show=$page->show();
		$data=$model->limit($page->firstRow,$page->listRows)->select();
//		dump($data);
		dump(explode(',',$data[4]['like']));die;
		$this->assign('data',$data);
		$this->assign('show',$show);
		$this->display();
	}

	public function charts(){
	    $model=M();
	    $data=$model->field('t2.name as deptname,count(*) as count')->table('sp_user as t1,sp_dept as t2')->where('t1.dept_id = t2.id')->group('deptname')->select();
	    $str='[';
	    foreach ($data as $k=>$v){
	        $str.="['".$v['deptname']."',".$v['count']."],";
        }
        $str=rtrim($str,',').']';
        $this->assign('str',$str);
	    $this->display();
    }
}
	
?>